package com.demo.datastructure.hashTable;

import com.demo.datastructure.hashTable.interFace.Table;

import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

/**
 * @description:
 * @author: ljr
 * @time: 2021/5/17 8:06
 */
public class HashTableDemo1<K,V> implements Table<K,V>{

    public static void main(String[] args){
        HashMap<String,String> map = new HashMap<>();
        map.put("AAA","BBB");
        map.get("AAA");
        for(Map.Entry entry : map.entrySet()){
            entry.setValue("1111");
        }
    }

    static final int DEFAULT_INITIAL_CAPACITY = 1 << 4;

    static final int DEFAULT_MAX_CAPACITY = 1 << 30;

    static final float DEFAULT_LOAD_FACTOR = 0.75f;

    Node<K,V>[] table;

    int size;


    public int size() {
        return size;
    }

    public Boolean isEmpty(){
        return  size == 0;
    }

    public V put(K key, V value){
        return putVal(hash(key), key, value, false, true);
    }

    final V putVal(int hash, K key, V value, boolean onlyIfAbsent,
                   boolean evict) {
         return value;
    }


    static final int hash(Object key) {
        int h;
        return (key == null) ? 0 : (h = key.hashCode()) ^ (h >>> 16);
    }

    private static class Node<K,V> implements Table.Entry<K,V>{
        final int hash;
        final K key;
        V value;
        Node<K,V> next;

        public Node(int hash, K key, V value, Node<K, V> next) {
            this.hash = hash;
            this.key = key;
            this.value = value;
            this.next = next;
        }


        public final K getKey(){
            return key;
        }


        public final V getValue(){
            return value;
        }


        public final V setValue(V newValue) {
            V oldValue = value;
            value = newValue;
            return oldValue;
        }

        public final int hashCode() {
            return Objects.hashCode(key) ^ Objects.hashCode(value);
        }

        public boolean equals(Object o){
            if(o == this){
                return  true;
            }

            if (o instanceof Map.Entry) {
                Map.Entry<?,?> e = (Map.Entry<?,?>)o;
                return Objects.equals(key, e.getKey()) &&
                        Objects.equals(value, e.getValue());
            }
            return false;
        }

    }

}
